import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      beforeEnter: (to, from, next) => {

        let token =sessionStorage.getItem('token')||localStorage.getItem('token')||""

       if (!token) {

         alert('请先登录')

         next("/login")

       } 

         next()

      }

    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('../views/Login.vue'),
    },
    {
      path: '/register',
      name: 'Register',
      component: () => import('../views/Register.vue'),
    },
    {
      path: '/idcard-verify',
      name: 'IDCardVerify',
      component: () => import('../views/IDCardVerify.vue'),
    }
  ],
})

export default router
